HW01

Task 1

Part a

Calculate the fraction of these points that are within distance 1 of the origin, giving an approximation of the volume of the unit hypersphere to the hypercube inscribing it. Plot this fraction as a function of D (a scatter plot of D versus the fraction).

Part b

Use the value of this fraction at D = 2 and D = 3 to get estimates for the value of $\pi$ as you know the area (for D = 2) and volume (for D = 3) formulae for these cases.

Since the area of a circle is $\pi$$R^2$, an estimation of the $\pi$ in 2 dimensional space would be the fraction of points which are within the distance of 1 to the origin times 4 because the radius of the circle with diameter as 1 unit is 1/2.

Since the volume of a sphere is $\frac{4}{3}$$\pi$$R^3$, an estimation of the $\pi$ in 3 dimensional space would be the fraction of points which are within the distance of 1 to the origin times 6 because the radius of the circle with diameter as 1 unit is 1/2.

Part c

Perform the calculations in part (b) with larger sample sizes. You can use the following set: {5000, 10000, 25000, 50000, 100000}. Visualize the estimated $\pi$ for D = 2 and D = 3 cases. Comment on your results

Estimates for $\pi$ in 2 dimensional space:

Estimates for $\pi$ in 3 dimensional space:

Notice that as the number of points simulated increases, for both dimensions, estimates for $\pi$ get closer and closer to the real value of $\pi$. In addition, notice that the estimations for pi at the small number of points are more accurate in the 3-dimensional simulation than the 2-dimensional simulation. This is simply because there is more information in the 3-dimensional case.

Part d

Repeat this simulation, sampling 1000 D-dimensional points from 1 to 15 dimensions, where the value in each dimension is uniformly randomly distributed between -1 and +1. For each value of D, generate an additional 100 test instances and calculate the distance to each test instance’s nearest neighbor. Plot the average distance from the test instances to their nearest neighbors as a function of D.

Task 2

Part a

Read image as a variable in R/Python. You need to install “jpeg” package to read image into a variable if you use R. For Python, an alternative is to use matplotlib package. What is the structure of the variable that stores the image? What is the dimension? a. Display the image.

Part b

Display each channel as separate image

Part c

For each channel, take the average of the columns and plot the average as a line plot for each channel on a single plot.

Part d

For each channel, subtract one half of the image from the other half (choice of halves is up to you but dividing the head image vertically into two parts make more sense). If you observe negative pixel values, you can make them equal to zero. Then:

• Display the new image.

• Display each channel separately as separate image.

Part e

In order to create a noisy image, add a random noise from uniform distribution with minimum value of 0 and a maximum value of “0.1 * maximum pixel value observed” to each pixel value for each channel of original image.

• Display the new image.

• Display each channel separately as separate image.

For all channels, the maximum pixel value observed is 255. Therefore, the noise will have a maximum value of 25.5 for all channels.